/**
 *
 */
package com.newer.config.freemarker;

import com.jagregory.shiro.freemarker.ShiroTags;
import freemarker.template.Configuration;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Shiro结合Freemarker标签
 * 自定义一个ShiroTagFreeMarkerConfigurer继承Spring本身提供的FreeMarkerConfigurer,
 * 目的是在FreeMarker的Configuration中添加shiro的配置
 *
 * @author xuntj
 * @create 2018-03-13 14:08
 **/
@Component
public class ShiroTagFreeMarkerConfigurer implements InitializingBean {

    @Autowired
    private Configuration configuration;

    @Override
    public void afterPropertiesSet() {
        ShiroTags tags = new ShiroTags();

        tags.put("attEq", new AttributeEqualTag());
        // 加上这句后，可以在页面上使用shiro标签
        configuration.setSharedVariable("shiro", tags);
    }
}
